import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:winkai/entity/subscribe_from.dart';
import 'package:winkai/helper/iap/iap_helper.dart';
import 'package:winkai/res/app_colors.dart';
import 'package:winkai/res/dimens.dart';
import 'package:winkai/ui/msg/controller/chat_controller.dart';
import 'package:winkai/utils/image_utils.dart';
import 'package:winkai/utils/page_jump_utils.dart';

class ChatTitleBar extends StatefulWidget {
  const ChatTitleBar({super.key, required this.controller});

  final ChatController controller;

  @override
  State<ChatTitleBar> createState() => _ChatTitleBarState();
}

class _ChatTitleBarState extends State<ChatTitleBar> {
  @override
  Widget build(BuildContext context) {
    var roleInfo = widget.controller.roleInfo;
    return SafeArea(
      left: false,
      bottom: false,
      right: false,
      child: Container(
        height: 48.w,
        padding: EdgeInsets.symmetric(horizontal: Dimens.mainHorizontalSpacing),
        child: Row(
          children: [
            GestureDetector(
              onTap: () {
                Get.back();
              },
              child: ImageUtils.getImage('ic_ai_back', 36.w, 36.w),
            ),
            SizedBox(width: 10.w),
            Expanded(
              child: GestureDetector(
                onTap: () {
                  widget.controller.jumpUserDetails();
                },
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    SizedBox(
                      width: double.infinity,
                      child: Text(
                        roleInfo.name ?? '',
                        maxLines: 1,
                        textAlign: TextAlign.center,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 18.sp,
                          color: Colors.black,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ),
                    SizedBox(
                      width: double.infinity,
                      child: Text(
                        roleInfo.aboutMe ?? '',
                        maxLines: 1,
                        textAlign: TextAlign.center,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 10.sp,
                          color: AppColors.color_4c,
                          fontWeight: FontWeight.w300,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            SizedBox(width: 10.w),
            Obx(() {
              IAPHelper().subscribeStatus.value;
              var isSubscribeVip = IAPHelper().isVip;
              return isSubscribeVip
                  ? SizedBox(
                      width: 36.w,
                      height: 36.w,
                    )
                  : GestureDetector(
                      onTap: () {
                        PageJumpUtils.toVipPage(SubscribeFrom.chatVip);
                      },
                      child: ImageUtils.getImage('ic_ai_root_vip', 36.w, 36.w),
                    );
            })
          ],
        ),
      ),
    );
  }
}
